package com.wyw.design.model.learning.behavioral.status;

/**
 * @Title   遥控器 扮演上下文角色，负责电视机状态切换
 * @Description
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/4/19 13:52
 * Update History:
 * Author        Time            Content
 */
public class RemoteControlMachine {
    // 包含电视机的三种状态：待机、关机、播放
    public final static TVState STANDBY_STATE = new StandByState();
    public final static TVState POWER_OFF_STATE = new PowerOffState();
    public final static TVState PLAY_STATE = new PlayState();
    // 标识当前状态
    private TVState currentState;
    // 获取当前状态
    public TVState getCurrentState() {
        return currentState;
    }
    // 设置当前状态，遥控器负责电视机的具体状态切换
    public void setCurrentState(TVState currentState) {
        this.currentState = currentState;
        this.currentState.setRemoteControlMachine(this);
    }

    // 委托给state统一去处理
    public void powerOn() {
        // 当前状态下如何powerOn，由state去确定
        this.currentState.powerOn();
    }
    public void powerOff() {
        this.currentState.powerOff();
    }
    public void play() {
        this.currentState.play();
    }
    public void standby() {
        this.currentState.standby();
    }
}
